package com.baizhi.cmfz.service.impl;

import com.baizhi.cmfz.dao.GuruDao;
import com.baizhi.cmfz.entiy.Guru;
import com.baizhi.cmfz.service.GuruService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class GuruServiceImpl implements GuruService {

    @Autowired
    private GuruDao dao;
    @Override
    public Map getGuruByPage(int page,int rows,String guruName) {
        Map map = new HashMap();
        //若用户名不等于null和空串
        if(guruName!=null && !"".equals(guruName)){
            guruName="%"+guruName+"%";//在java代码中拼接好，可以屏蔽数据库的差异
        }else{
            guruName=null;
        }

        int total = dao.getTotal(guruName);
        map.put("total", total);

        int start=(page-1)*rows;
        int pageSize=rows;
        List<Guru> list = dao.getGuruByPage(start,pageSize,guruName);

        map.put("rows", list);
        //System.out.println(map);
        return map;
    }

    @Override
    public void  add(Guru guru) {
        dao.insert(guru);

    }

    @Override
    public void update(Guru guru) {
        dao.update(guru);
    }

    @Override
    public void multiDelete(int[] ids) {
        dao.multiDelete(ids);
    }

    @Override
    public List<Guru> selectAll() {
        return dao.selectAll();
    }
}
